Involver Developer Network : Chapter 3 - Aquaman Movie Premiere
This page last changed on Sep 13, 2011 by kristin.bradley@involver.com.
This chapter covers the development of a simple application which engages users with an interactive poll. The walkthrough builds on Chapter 2 - it assumes you are familiar with feature blocks and the {% for %} tag. After completing this chapter you'll be able to integrate interactive polls and common social elements like commenting, be introduced to the {% if %} tag, and understand how to introduce localization in your SML application. Aquaman Movie PremiereAquaman Move Premiere is an example of using polls to gather customer feedback. We'll let fans on Facebook decide which city the highly anticipated summer movie Aquaman will debut it's premiere showing. The cities from which fans can choose from are San Francisco, Los Angeles, Boston or Chicago. Let's get started! Adding the Poll Feature Block
First, we are using the {% poll %} Feature Block to specify we want a poll in our application. We've omitted the optional name attribute – the name has been automatically set to default for us. Next we iterate through the poll items in the block's context variable. This shows the latest, non-hidden polls. For each poll we show each option with a radio button which when clicked will respond to the poll. We use the index0 attribute on the forloop context variable to get back the current index of our iteration (0 for the first option, 1 for the second, etc.) which we then pass to a built-in javascript helper – respond_to_poll() – along with the current poll's id. The standard results dialog is shown with the current results. Adding comments with the facebook_comments social tagSince we already have the ability to share the poll to our feed via the standard results dialog, let's add the ability to comment on each individual poll.
We've added a new div container which will house the comments area for each poll. Then, using the facebook_comments social tag, we've specified a wall of comments for the current poll in our iteration of polls. facebook_comments, like many other social tags, can be passed content managed by a feature block. Here we've added comments to our poll items. We could just as easily add facebook_like or facebook_send in a similar fashion, or use these social tags across other features such as the daily deals in the rss_feed feature block from the prior chapter. Poll ManagementPolls can be managed without code modification. Adding a Poll - A new poll can be added by selecting 'Add New Poll' in the settings area for the poll feature block. By default, the most recent poll will always show first. Viewing Results - You can view the results of a poll by selecting 'Poll Results'. The results show both absolute votes as well as relative distribution. Hiding a Poll - Polls can be hidden, such that they will no longer be shown; The poll.poll_items context variable only returns non-hidden polls. A hidden poll can be unhidden and shown again. Deleting a Poll - A poll can be remove completely by selecting 'Delete Poll'. This will remove the poll from poll.poll_items as well as remove the configuration and any results. Familiarize yourself with the above management features by trying them out on your default poll feature block. Start by adding an additional poll, then hiding the original poll. How does the application change as you make these changes? Adding Localization with the current_locale variableSince the movie is debuting in North America, the movie studio would like to restrict voting to only english-speaking US audiences. We can easily add this gating by leveraging the current_locale global context variable in conjunction with the {% if %} tag.
Introduction to the if tagLike any modern programming language, SML has support for if/else, often called conditional logic. The if/else tag allows you to introduce dynamic control flow into your applications. We use it here to check the value of the user's locale and display content appropriately. The tag takes a single argument, an expression that returns a boolean value. An expression can either be a boolean variable or a statement that uses one of the boolean logic operators (==, !=, or, and, etc.) to compare values. Next StepsYou've now built an application that serves an interactive poll to US audiences. Take a look at the links below to read up more about the poll feature block. Try experimenting with a different presentation of the options and see if you can change out the standard results experience. content_comments has many options you can customize, see if you can remove the metadata around each comment. poll On to Chapter 4![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
Document generated by Confluence on Feb 12, 2013 09:09 |